//
//  ViewController.m
//  28-UIViewAnimation(2)
//
//  Created by 鹏飞罗 on 16/8/22.
//  Copyright © 2016年 罗鹏飞. All rights reserved.
//

#import "ViewController.h"
#import "UIView+ChangeFrame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *animationView;
@property (nonatomic, strong) UIButton *animationButton;
@property (nonatomic, strong) UIButton *animationButtonTwo;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    self.animationView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_animationView];
    self.animationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.animationButton.frame = CGRectMake(100, 100, 200, 200);
    _animationButton.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:_animationButton];
    
    [_animationButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.animationButtonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
    self.animationButtonTwo.frame = CGRectMake(200, 200, 100, 100);
    self.animationButtonTwo.backgroundColor = [UIColor blackColor];
//    [self.view addSubview:_animationButtonTwo];
   // 参数1:
   // 参数2：
    // 参数3 ：0.0 ~ 1.0  数值越小阻力越小， 数值越大阻力越大
   // 参数4 ： 速度
   // 参数5：选项
//    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
//        _animationView.z_width = 100;
//        _animationView.z_height = 300;
//        _animationView.backgroundColor = [UIColor yellowColor];
//    } completion:^(BOOL finished) {
//        
//    }];
    
}

- (void) buttonClicked:(UIButton *) button {
    
   // 参数1： 需要执行动画的View
   // 参数2： 持续时间
   // 参数3： 动画效果
//    [UIView transitionWithView:_animationButton duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
//        _animationButton.z_height = 100;
//        
//    } completion:^(BOOL finished) {
//  // 动画可以嵌套动画
//        [UIView animateWithDuration:0.5 animations:^{
//            _animationButton.z_height = 200;
//        }];
//        
//        
//    }];
    
    
    // toView added to fromView.superview, fromView removed from its superview
    
    //toView会被添加到fromView的父试图上， 然后fromView被从父试图上移除
    [UIView transitionFromView:_animationButton toView:_animationButtonTwo duration:5 options:UIViewAnimationOptionTransitionCurlDown completion:^(BOOL finished) {
        
    }];
    
    
    
}

- (void)viewDidAppear:(BOOL)animated {
    [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
        _animationView.z_width = 100;
        _animationView.z_height = 300;
        _animationView.backgroundColor = [UIColor yellowColor];
    } completion:^(BOOL finished) {
        
    }];
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
